package twoSum;

import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;

public class Solution {
    class Node{
        public int index;
        public int value;

        public Node(int index, int value) {
            this.index = index;
            this.value = value;
        }
    }
    public int[] twoSum(int[] nums, int target) {
        // 和为target
        Node[] nodes = new Node[nums.length];
        for (int i = 0; i < nodes.length; i++) {
            nodes[i] = new Node(i,nums[i]);
        }
        Arrays.sort(nodes, new Comparator<Node>() {
            @Override
            public int compare(Node o1, Node o2) {
                return o1.value - o2.value;
            }
        });
        for (int i = 0; i < nodes.length; i++) {
            for (int j = i+1; j < nodes.length; j++) {
                if(nodes[i].value+nodes[j].value == target){
                    return new int[]{nodes[i].index,nodes[j].index};
                }
            }
        }
        return new int[]{};
    }
}
//class Solution {
//    public int[] twoSum(int[] nums, int target) {
//        Map<Integer, Integer> hashtable = new HashMap<Integer, Integer>();
//        for (int i = 0; i < nums.length; ++i) {
//            if (hashtable.containsKey(target - nums[i])) {
//                return new int[]{hashtable.get(target - nums[i]), i};
//            }
//            hashtable.put(nums[i], i);
//        }
//        return new int[0];
//    }
//}